using System;
using System.ComponentModel;
using System.Reflection;
using System.Windows.Forms;

namespace ICSharpCode.TextEditor.Extensions
{
	public static class ControlExtensions
	{
		public static EventHandlerList GetEventHandlerList(this Control c)
		{
			return ControlExtensions.GetEventHandlerListInternal(c);
		}

		public static EventHandlerList GetEventHandlerList(this Component c)
		{
			return ControlExtensions.GetEventHandlerListInternal(c);
		}

		private static EventHandlerList GetEventHandlerListInternal(object obj)
		{
			Type type = obj.GetType();
			PropertyInfo property = type.GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic);
			return (EventHandlerList)property.GetValue(obj, null);
		}
	}
}
